﻿@{
    ViewBag.Title = "Errors";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<div id="alert_placeholder" style="margin-top: 15px; padding-bottom: 15px;"></div>
<div class="form-group">
    <div class="col-lg-3">
        <input id="TXTSearchString" type="text" placeholder="Search Box" class="form-control">
    </div>
    <a id="btnSearch" class="btn btn-sm btn-default">Search</a>
</div>
<div class="widget">
    <div class="widget-head">
        <div class="pull-left">Error Log</div>
        <div class="clearfix"></div>
    </div>
    <div class="widget-content">
        <table class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th>Title</th>
                    <th>Error Code</th>
                    <th>Date Of Error</th>
                    <th>Description</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody data-bind="foreach: pageData()" style="margin-top: 50px">
                <tr>
                    <td data-bind="text: ErrorTitle"></td>
                    <td data-bind="text: ErrorCode"></td>
                    <td data-bind="text: moment(CreatedDate()).format('DD MMM, YYYY h:mm:ss a')"></td>
                    <td data-bind="text: Description"></td>
                    <td>
                        <a data-bind="event: { click: DeleteData }" class="fa fa-times"  href="javascript:void(0);" title="Delete Record"></a>
                    </td>
                </tr>
            </tbody>
        </table>
        <div class="widget-foot">
             <ul class="pagination pagination-sm pull-right">
                 <li><a id="FirstPageButton" href="javascript:void(0)">First</a></li>
                 <li><a id="prevPageButton" href="javascript:void(0)">Prev</a></li>
                <li data-bind="foreach: ko.utils.range(1, pager())"><a data-bind="attr: {text :  $data }, text : $data" href="javascript:void(0)"  class="pageNumber"></a></li>
                <li><a  id="nextPageButton"  href="javascript:void(0)">Next</a></li>
                 <li><a id="LastPageButton" href="javascript:void(0)">Last</a></li>
            </ul>
            <div class="clearfix"></div>
        </div>
    </div>
</div>

@section scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#h2Title').html("<i class='fa fa-cogs'></i> ErrorLog");
            $('#aTitle').html("Error Log");
            $('#liErrorLog').addClass("open");

            DeleteData = function (obj, event) {
                $("#modalContent").load('/Admin/ErrorLog/Delete?ErrorID=' + obj.ErrorID(), function () {
                    $('#modalDiv').modal({
                        backdrop: 'static',
                        keyboard: true
                    }, 'show');
                });
            }
        });
        function alertTimeout(wait) {
            setTimeout(function () {
                $('#alert_placeholder').children('.alert:first-child').remove()
            }, wait);
        }
        bootstrap_alert = function () { }

        bootstrap_alert.success = function (message) {
            $('#alert_placeholder').html('<div class="alert alert-success"><a hreaf="#" class="close" data-dismiss="alert">×</a><strong>' + "Sucess! " + '</strong><span>' + message + '</span></div>')
            alertTimeout(3000);
        }

        var loadPage = function (pageNumber, pageSize, searchString) {
            $.ajax({
                url: "/Admin/ErrorLog?pageNumber=" + pageNumber + "&pageSize=" + pageSize + "&searchString=" + searchString + "&pgindex=10&columnFilter=" + '',
                type: "POST",
                success: function (data) {
                    if (vm == null) {
                        vm = new viewModel(data);
                        if ((vm.maxPageIndex() + 1) >= 5) {
                            $("#nextPageButton").css({ "display": "initial" });
                        }
                        ko.applyBindings(vm);
                        return data.Data.length;
                    }
                    else {
                        vm.pageData(ko.observableArray());
                        vm.pageData(ko.mapping.fromJS(data.Data));
                        vm.maxPageIndex(Math.ceil(data.RecordCount / $("#rowsPerPage").val()) - 1);
                        if ((vm.maxPageIndex() + 1) <= 5) {
                            $("#prevPageButton").css({ "display": "none" });
                            $("#nextPageButton").css({ "display": "none" });
                        }
                        else if ((vm.maxPageIndex() + 1) >= 5 && !vm.isLastPage()) {
                            $("#nextPageButton").css({ "display": "intial" });
                        }
                        else if ((vm.maxPageIndex() + 1) >= 5 && !vm.isFirstPage()) {
                            $("#prevPageButton").css({ "display": "intial" });
                        }
                        return data.Data.length;
                    }
                }
            });
        }
    </script>
}@Scripts.Render("~/bundles/pagedlist")